<%@ page import="java.sql.*" %><%--
  Created by IntelliJ IDEA.
  User: xlro
  Date: 2021/4/20
  Time: 23:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>第二个页面</title>
</head>
<body>

<%
    request.setCharacterEncoding("utf-8");
    String username = request.getParameter("username");
    String password = request.getParameter("password");

    Class.forName("com.mysql.jdbc.Driver");
    try(Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/library?serverTimezone=UTC&characterEncoding=utf-8",
                "root","root")){
            String sql = "select * from borrow_card where username = ?";
            try(PreparedStatement preparedStatement = conn.prepareStatement(sql)){
                preparedStatement.setString(1,username);
                try(ResultSet resultSet = preparedStatement.executeQuery()){
                    while (resultSet.next()){
                        if(password.equals(resultSet.getString("password"))){
                            response.sendRedirect("./main.jsp");
                        }else{
%>
        <jsp:forward page="index.jsp"></jsp:forward>
<%
                        }
                    }
                }
            }
    }catch (SQLException e){
        e.printStackTrace();
    }


    out.print("[err!]无法进入数据库\n请检查是否打开mysql数据库！");
%>

</body>
</html>
